package cn.ht.bootdemo.common.exception;

import cn.ht.bootdemo.common.entity.ResultVo;
import cn.ht.bootdemo.common.enums.ResponseStatusEnum;
import cn.ht.bootdemo.common.utils.R;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseStatus;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import javax.servlet.http.HttpServletResponse;
import javax.validation.ConstraintViolationException;

/**
 * 全局异常信息处理
 * 
 */
@RestControllerAdvice
@Slf4j
public class GlobalExceptionHandler {

    @ExceptionHandler(ConstraintViolationException.class)
    @ResponseStatus(HttpStatus.BAD_REQUEST)
    public ResultVo exceptionHandler(ConstraintViolationException e, HttpServletResponse response){
        log.error(e.getMessage());
        return R.build(ResponseStatusEnum.NULL_PARAMETER.getStatus(), ResponseStatusEnum.NULL_PARAMETER.getMessage(),null);
    }


}
